/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tkgarment.system.action;

import com.tkgarment.system.dao.DepartmentDAO;
import com.tkgarment.system.dao.ReportDAO;
import com.tkgarment.system.domain.Department;
import com.tkgarment.system.domain.Report;
import com.tkgarment.system.factory.DAOFactory;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.interceptor.SessionAware;

/**
 *
 * @author user
 */
public class EmpReportAction extends ActionSupportBase implements SessionAware{

    
    Map<String, Object> session;
    List<Report> report;
    List<Department> listDepartment;
    Department dept;
    String filter;
    String reportName;
    
     public String reportBirthday(){
        try {
            ReportDAO dao = DAOFactory.createReportDao();
            DepartmentDAO deptDao = DAOFactory.createDepartmentDao(); 
            setListDepartment(deptDao.getAll());
            setReport(dao.getReportBirthday());
            
            return SUCCESS;
        } catch (Exception ex) {
            Logger.getLogger(EmpReportAction.class.getName()).log(Level.SEVERE, null, ex);
            return ERROR;
        }
    }
    
    public String reportSex(){
        try {
            ReportDAO dao = DAOFactory.createReportDao();
            setReport(dao.getReportSex());
            
            return SUCCESS;
        } catch (Exception ex) {
            Logger.getLogger(EmpReportAction.class.getName()).log(Level.SEVERE, null, ex);
            return ERROR;
        }
    }
    
     public String reportEmpType() {
        try {
           ReportDAO dao = DAOFactory.createReportDao();
           DepartmentDAO deptDao = DAOFactory.createDepartmentDao(); 
            setListDepartment(deptDao.getAll());
            
            if (StringUtils.isNotEmpty(filter) == true && filter.compareTo("-1") != 0) {
                setDept(deptDao.getById(filter));
                setReportName("รายงานจำนวนพนักงานแบ่งตามประเภทพนักงานหน่วยงาน : " + dept.getDepartmentName());
                
                 setReport(dao.getReportEmpType(filter));
            }else{
                 setReportName("รายงานจำนวนพนักงานแบ่งตามประเภทพนักงาน");
                setReport(dao.getReportEmpType());
            }
            if (report.size() == 0) {
                reportName = "ไม่มีข้อมูล";
            }
            
           
            
             return "success";
            
        } catch (Exception ex) {
             Logger.getLogger(EmpReportAction.class.getName()).log(Level.SEVERE, null, ex);
            return ERROR;
        }
       
    }
    
    public String reportGraduation() {
        try {
           ReportDAO dao = DAOFactory.createReportDao();
            DepartmentDAO deptDao = DAOFactory.createDepartmentDao(); 
            setListDepartment(deptDao.getAll());
           
            
             if (StringUtils.isNotEmpty(filter) == true && filter.compareTo("-1") != 0) {
                setDept(deptDao.getById(filter));
                setReportName("รายงานจำนวนพนักงานแบ่งตามวุฒิการศึกษาของพนักงานหน่วยงาน : " + dept.getDepartmentName());
                setReport(dao.getReportGraduation(filter));
                
            }else{
                 setReportName("รายงานจำนวนพนักงานแบ่งตามวุฒิการศึกษาของพนักงาน");
                setReport(dao.getReportGraduation());
            }
            if (report.size() == 0) {
                reportName = "ไม่มีข้อมูล";
            }
            
            
           
             return "success";
            
        } catch (Exception ex) {
             Logger.getLogger(EmpReportAction.class.getName()).log(Level.SEVERE, null, ex);
            return ERROR;
        }
       
    }
    
    
    
    public String displaystat(){
        
        try {
             ReportDAO dao = DAOFactory.createReportDao();
              DepartmentDAO deptDao = DAOFactory.createDepartmentDao(); 
            setListDepartment(deptDao.getAll());
            
            if (StringUtils.isNotEmpty(filter) == true && filter.compareTo("-1") != 0) {
                setDept(deptDao.getById(filter));
                setReportName("รายงานจำนวนพนักงานแบ่งตามเพศหน่วยงาน : " + dept.getDepartmentName());
                 setReport(dao.getReportSex(filter));  
            }else{
                 setReportName("รายงานจำนวนพนักงานแบ่งตามเพศ");
                 setReport(dao.getReportSex()); 
            }
            if (report.size() == 0) {
                reportName = "ไม่มีข้อมูล";
            }
          
            
        } catch (Exception ex) {
            ex.printStackTrace();
            setMessage(ex.getMessage());
            Logger.getLogger(EmpReportAction.class.getName()).log(Level.SEVERE, null, ex);
        }
        return "none";
    }

    public List<Report> getReport() {
        return report;
    }

    public void setReport(List<Report> report) {
        this.report = report;
    }

    public String getFilter() {
        return filter;
    }

    public void setFilter(String filter) {
        this.filter = filter;
    }

    public Department getDept() {
        return dept;
    }

    public void setDept(Department dept) {
        this.dept = dept;
    }

    public String getReportName() {
        return reportName;
    }

    public void setReportName(String reportName) {
        this.reportName = reportName;
    }
    
    
    
    
    
    public Map<String, Object> getSession() {
        return session;
    }

    public List<Department> getListDepartment() {
        return listDepartment;
    }

    public void setListDepartment(List<Department> listDepartment) {
        this.listDepartment = listDepartment;
    }
    
    
    
    
    @Override
    public void setSession(Map<String, Object> map) {
       this.session = map;
    }
    
}
